import type {CatColumn} from "./CatColumn";

export interface ActionItem {
    key: string;
    title: string;
    confirm?: string;
}

export interface ActionColumn<T = any> extends CatColumn<T> {
    items: ActionItem[];
    more?: ActionItem[];
}

export const ActionTypes = {
    get edit(): ActionItem {
        return {key: 'edit', title: '编辑'};
    },
    get delete(): ActionItem {
        return {key: 'delete', title: '删除', confirm: '确认要删除该记录吗?'};
    }
}

export type ActionTypeName = keyof typeof ActionTypes;

export function defaultAction(more?: ActionItem[]): ActionColumn {
    return <ActionColumn>{
        title: '操作',
        type: 'action',
        items: [ActionTypes['edit'], ActionTypes['delete']],
        more: more
    };
}